package org.hyh.core.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.Getter;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * @auther :hyh
 * @desc :
 * @date :2020/7/11
 */
@Data
@Accessors(chain = true)
@TableName("sys_user")
public class SysUser implements UserDetails {

    private  String id;
    private String   createdBy;

    private  String  lastModifiedBy;
    private Date lastModifiedDate;

    private  String  username;
    private  String  password;
    private  String  nickname;
    private  String  phone;
    private  String  email;
    private  String  avatar;
    private  String  qqOpenId;
    private  String  wxOpenId;
    private  Integer  available;
    private  String description;
    private  Integer  version;
    private  Integer delFlag;

    private String deptId;

    @TableField(exist = false)
    List<GrantedAuthority> list;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return list;
    }


    public Collection<? extends GrantedAuthority> setAuthorities(List<GrantedAuthority> list) {
        return this.list=list;
    }



    //########################################################################
    //        ** 以下的会在UserDetailsService#loadUserByUsername()  调用完毕后，执行各种 XXXchecks()时调用。
    //        ** 也可以重写这些xxChecks()方法，用于验证码的校验。
    //########################################################################
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
